package com.morningstar.logger.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.morningstar.common.dao.entity.CommonQuery;
import com.morningstar.common.result.Result;
import com.morningstar.logger.dao.entity.SysLogOperate;
import com.morningstar.logger.service.SysLogOperateService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.morningstar.common.constants.permission.PermissionConstants.DETAIL;
import static com.morningstar.common.constants.permission.PermissionConstants.LIST;

/**
 * 操作日志接口
 *
 * @author Admin
 */
@Slf4j
@RestController
@RequestMapping("/logger/operate")
public class SysLogOperateController {

    private static final String PERMISSION = "logger.operate";

    private static final String PERMISSION_LIST = PERMISSION + LIST;

    private static final String PERMISSION_DETAIL = PERMISSION + DETAIL;

    @Resource
    private SysLogOperateService logOperateService;

    @PostMapping("/list")
    @SaCheckPermission(PERMISSION_LIST)
    public Result<IPage<SysLogOperate>> list(CommonQuery<SysLogOperate, SysLogOperate> commonQuery) {

        LambdaQueryWrapper<SysLogOperate> queryWrapper = new LambdaQueryWrapper<>();

        return Result.successData(logOperateService.page(commonQuery.getPage(), queryWrapper));
    }

    @PostMapping("/detail")
    @SaCheckPermission(PERMISSION_DETAIL)
    public Result<SysLogOperate> detail(Long logId) {
        return Result.successData(logOperateService.getById(logId));
    }
}
